/*
 * @Author: your name
 * @Date: 2021-02-19 14:25:03
 * @LastEditTime: 2021-04-24 00:14:31
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \guzheng\server\db.js
 */
const mysql = require('mysql');

const pool = mysql.createPool({
    host: 'localhost',
    port: 3306,
    user: 'root',
    password: '123456',
    database: 'guzheng',
})

module.exports = (sql, params) => {
    return new Promise((resolve, reject) => {
        pool.getConnection((err, connection) => {
            if (err) throw err;
            connection.query(sql, params, (err, result, fields) => {
                connection.release(); // 释放连接
                if (err) reject(err);
                resolve(result)
            })
        })
    })
}